<?php
include_once("includes/common.php");
include_once("class/User.class.php");
include_once("class/Explore.class.php");
require_once("islogin.php");
if ($islogin!=1&&!isset($_GET['id'])){
    header('Location: login.php');
    exit;
}
$pageName = "个人中心";

//menu头像等于现在登录的
$menuavatar = !$user_info["message"]["avatar"] ? "/data/avatar/default.jpg" : $user_info["message"]["avatar"];
$isme = true;
$meuid = $user_info['message']['user_id'];
if(isset($_GET['id'])){
    $profile_id = $_GET['id'];
    if (!isUid($profile_id)){
        header('Location: profile.php');
        return;
    }

    $explore = new Explore();
    $uinfo = json_decode($explore->getUserInfo($_GET['id']),true);
    if (!$uinfo){
        header('Location: profile.php');
        return;
    }
    //var_dump($uinfo['user_id']);
    if ($uinfo['user_id']!=$user_info['message']['user_id']){
        //覆盖
        $isme = false;
        //已经关注他的ID下有没有我的ID，粉丝我的ID下有没有他的ID
        if($islogin==1){
            $isfans = $explore->getIsFans($meuid,$uinfo['user_id']);
            $isfollow = $explore->getIsFans($uinfo['user_id'],$meuid);
        }
        $user_info['message'] = $uinfo;
    }
}


$age = $user_info['message']['birthday'] ? calculateAge($user_info['message']['birthday']) : null;

$genderIcon = ($user_info['message']['gender'] == 1) ? 'static/img/boy.svg' : 'static/img/girl.svg';

$avatar = !$user_info["message"]["avatar"] ? "data/avatar/default.jpg" : $user_info["message"]["avatar"];


$user_statistics = json_decode($user->user_statistics($user_info['message']['user_id']), true);
//$explore = new Explore();
//var_dump(json_decode($explore->likeNotes($user_info['message']['user_id'],12,1,1),true));
//var_dump(json_decode($explore->profileNotes($user_info['message']['user_id'],12,1),true));

function calculateAge($birthday) {
    if ($birthday==null){
        return null;
    }
    $birthDate = new DateTime($birthday);
    $currentDate = new DateTime();
    $age = $currentDate->diff($birthDate)->y;
    return $age;
}
?>
<!DOCTYPE html>
<html>
<?php require_once('head.php'); ?>
	<body>
    <?php require_once('header.php'); ?>
		<div class="container-fluid content">
			<div class="row">
                <?php require_once('menu.php'); ?>
				<div class="col watercon">
					<div class="row profile_content">
						<div class="col-5 text-end">
                            <img src="<?php echo $avatar; ?>" class="profile_avatar" alt="" />
						</div>
						<div class="col-4 text-start phead_right_content">
							<div class="profile_nickname"><?php echo $user_info["message"]["nickname"];?></div>
							<div class="profile_uid">小蓝书号：<?php echo $user_info["message"]["blue_id"];?></div>
							<div class="profile_udesc"><?php if($user_info["message"]["description"]){echo $user_info["message"]["description"];}else{echo "还没有简介";}?></div>
							<div class="profile_uold">
                                <?php if ($user_info["message"]["gender"] !== null && $age !== null){ ?>
                                    <span class="oldcirc"><?php if($user_info["message"]["gender"]!== null){?><img src="<?php echo $genderIcon;?>" alt="" /><?php }?> <?php if($user_info["message"]["gender"]!== null){?><?php echo $age;?>岁<?php }?></span>
                                <?php }?>
                                <?php if(getIpProvince($user_info["message"]["ip"])){?>
                                    <span class="oldcirc">IP：<?php echo getIpProvince($user_info["message"]["ip"]);?></span>
                                <?php }?>
                                <?php if(!$isme){?>
                                    <?php if($isfans){?>
                                        <span class="oldcirc circfans">ta是你的粉丝</span>
                                    <?php }?>
                                    <?php if($isfollow){?>
                                        <span class="oldcirc circfollow">✓ 已关注</span>
                                    <?php }?>
                                <?php }?>
							</div>
							<div class="profile_unum"><span class="profile_likenum"><?php echo $user_statistics['message']['following_count']?> <span class="unum_cn">关注</span> </span><span
									class="profile_likenum"><?php echo $user_statistics['message']['fans_count']?> <span class="unum_cn">粉丝</span></span><span class="profile_likenum"><?php echo $user_statistics['message']['likes_received_count']?> <span class="unum_cn">获赞与收藏</span></span>
							</div>
						</div>
                        <div class="col text-start follow_btn" style="padding-top: 10px">
                            <?php if(!$isme){?>
                                <?php if($isfollow){?>
                                    <button class="follows_btn" id="followButton" data-fans-id="<?php echo $meuid;?>" data-uid="<?php echo $_GET['id'];?>">已关注</button>
                                <?php }else{?>
                                    <button id="followButton" data-fans-id="<?php echo $meuid;?>" data-uid="<?php echo $_GET['id'];?>">关注</button>
                                <?php }?>
                            <?php }?>
                        </div>
                        <div class="row ptabrow">
							<div class="col ptabBtn">
                                <button id="ptabBtnactive" data-hash="#note">笔记</button>
                                <button data-hash="#favorite">收藏</button>
                                <button data-hash="#like">点赞</button>


                            </div>
						</div>
						<div class="row pnote_info">
                            <!--瀑布流start-->
                            <div class="row text-start water profile_note" id="notesContainer">


                            </div>
                            <!--瀑布流end-->

                            <!--无内容显示-->
                            <div class="col" id="noNote">
                                <!--<div class="nullcirc" style="">
                                    <img src="static/img/null.svg" alt=""/>
                                </div>-->
                                <div class="nulltips notify_end">- THE END -</div>
                            </div>
                            <!--无内容end-->
						</div>
					</div>
				</div>
			</div>
		</div>

        <div class="flash_btn" onclick="location.reload();">
            <img src="static/img/flash.svg" alt="" />
        </div>
        <div class="flash_btn_text" id="flash_text">刷新</div>
        <div class="up_btn">
            <img src="static/img/up.svg" alt="" />
        </div>
        <div class="up_btn_text" id="up_text">回到顶部</div>

        <script>
            let uid = '<?php echo $user_info['message']['user_id'];?>';
            let meuid = '<?php echo $meuid;?>';
            let apiType = 'usernote';
            let page = 1;
            let keyword = '';
            let note_type = 3;
        </script>
        <script src="static/js/jquery.min.js"></script>
        <script src="static/js/masonry.pkgd.min.js"></script>
        <script src="static/js/imagesloaded.pkgd.min.js"></script>
        <script src="static/js/message.min.js"></script>
        <script src="static/js/custom.js"></script>
        <script src="static/js/exp-api.js"></script>
        <script src="static/js/profile.js"></script>
	</body>
</html>